<?php 
session_start(); 
require_once('include/connect.inc.php'); 
if($_SESSION['sess_id'] <> session_id()){
?>
 <SCRIPT LANGUAGE="JavaScript">
			alert("กรุณาเข้าสู่ระบบให้ถูกต้องตามขั้นตอน...!");
			location="login.php";
</script>
<?php }?>
<?php
$msg="";
	$query = query("SELECT * FROM tb_student where  r_student_id='".$_GET[student_id]."'");
		while ($rs = fetch_array($query)) {
			$r_student_id = $rs['r_student_id'];
			$student_password = $rs['student_password'];
			$student_fname = $rs['student_fname'];
			$student_lname = $rs['student_lname'];
			$fac_name = $rs['fac_name'];
			$major_name = $rs['major_name'];
			$year = $rs['year'];
			$student_email = $rs['student_email'];
			$student_phone = $rs['student_phone'];
			}
			if($_GET[op]=="editstudent"){
			$strSql="update tb_student set r_student_id='".$_POST[r_student_id]."',student_fname='".$_POST[student_fname]."',student_lname='".$_POST[student_lname]."',student_password='".$_POST[student_password]."',year='".$_POST[year]."',fac_id='".$_POST[fac_id]."',major_id='".$_POST[major_id]."',student_email='".$_POST[student_email]."',student_phone='".$_POST[student_phone]."' where r_student_id='".$_POST[student_id]."'";
		$rs = execute($strSql);
	if(!$rs) {
		$msg = "เกิดข้อผิดพลาดโปรดทำรายการใหม่";
			header("location:person_show_stu.php");
	} else {
			?>
   			 <SCRIPT LANGUAGE="JavaScript">
			alert("คุณได้ทำการแก้ไขข้อมูลผู้ทำข้อสอบเรียบร้อยแล้ว...!");
			location="person_show_stu.php";
			</script>
			<?
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Model Test Program</title>
<link rel="stylesheet" type="text/css" href="template/template_style_wood.css">

<script language = "JavaScript">

		//**** List Province (Start) ***//
		function ListProvince(SelectValue)
		{
			frmMain.major_id.length = 0
			
			//*** Insert null Default Value ***//
			var myOption = new Option('','')  
			frmMain.major_id.options[frmMain.major_id.length]= myOption
			
			<?
			$intRows = 0;
			$strSQL = "SELECT * FROM tb_major ORDER BY major_id ASC ";
			$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
			$intRows = 0;
			while($objResult = mysql_fetch_array($objQuery))
			{
			$intRows++;
			?>			
				x = <?=$intRows;?>;
				mySubList = new Array();
				
				strGroup = <?=$objResult["fac_id"];?>;
				strValue = "<?=$objResult["major_id"];?>";
				strItem = "<?=$objResult["major_name"];?>";
				mySubList[x,0] = strItem;
				mySubList[x,1] = strGroup;
				mySubList[x,2] = strValue;
				if (mySubList[x,1] == SelectValue){
					var myOption = new Option(mySubList[x,0], mySubList[x,2])  
					frmMain.major_id.options[frmMain.major_id.length]= myOption					
				}
			<?
			}
			?>																	
		}
		//**** List Province (End) ***//

</script>
</head>

<body>
<div id="menu"><div><img src="../images/icon-m.png" /></div>
<div id="menulinks">
		<a class="active" href="person.php">จัดการบุคลากร</a>
		<a  href="problem/admin_resive.php">ตรวจสอบความคิดเห็น</a>
        <a  href="new/manage_news.php">ประกาศข่าวสาร</a>
        <a href="logout.php">ออกจากระบบ</a>
		</div></div>
        
      <div id="p3">    
<div id="header"></div>
<div id="page"><div id="p1">คุณ<?php echo"$admin_name";?><hr />
    <form name="frmMain"  id="frmAddmin" action="person_edit_stu.php?op=editstudent" method="post">
     <?php echo$msg; ?>
     <table class="p21" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <th align="left">แก้ไขข้อมูลผู้ทำข้อสอบ</th>
        <th align="right"><a href="person_show_stu.php"><img src="images/undo.png" border="0" /></a></th>
      </tr>
    </table>
	 <table border="0" cellspacing="0" cellpadding="0" id="table-e">
        <tr>
          <th>รหัสประจำตัว :</th>
          <td width="60%"><input type="text" name="r_student_id" id="r_student_id" value="<? echo $r_student_id;?>" /></td>
          </tr>
        <tr>
          <th>รหัสผ่าน :</th>
          <td><input type="text" name="student_password" id="student_password" value="<? echo $student_password;?>"/></td>
          </tr>
        <tr>
          <th>ชื่อ :</th>
          <td><input type="text" name="student_fname" id="student_fname" value="<? echo $student_fname;?>" /></td>
        </tr>
        <tr>
           <th>นามสกุล :</th>
          <td><input type="text" name="student_lname" id="student_lname" value="<? echo $student_lname;?>"/></td>
        </tr>
        <tr>
          <th>คณะ :</th>
          <td>
          <select id="fac_id" name="fac_id" onChange = "ListProvince(this.value)">
          <?
			$strSQL = "SELECT * FROM tb_fac ORDER BY fac_id  ";
			$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
			while($objResult = mysql_fetch_array($objQuery))
			{
			?>
 			<option  value="<?=$objResult["fac_id"];?>"<? if($fac_id== $objResult["fac_id"]) echo " selected='selected'"; ?>>
			<?=$objResult["fac_name"];?></option>
     	     <?	}	?>
        </select>
         </td>
          </tr>
        <tr>
          <th>สาขาวิชา :</th>
          <td><select name="major_id" id="major_id" class="txtbox">
            <?
		  $query = query("SELECT * FROM tb_major");
		  while ($rs = fetch_array($query)){
		  ?>
            <option value="<? echo $rs[major_id]; ?>"<? if($major_id==$rs[major_id]) echo " selected='selected'"; ?>><? echo $rs[major_name];?></option>
            <? }?>
          </select></td>
          </tr>
        <tr>
         <th>ชั้นปีที่ :</th>
          <td>
          <select name="year" id="year">
          <option value="<? echo "1";?>"<? if($year== 1) echo " selected='selected'"; ?>><? echo "1";?></option>
          <option value="<? echo "2";?>"<? if($year== 2) echo " selected='selected'"; ?>><? echo "2";?></option>
          <option value="<? echo "3";?>"<? if($year== 3) echo " selected='selected'"; ?>><? echo "3";?></option>
          <option value="<? echo "4";?>"<? if($year== 4) echo " selected='selected'"; ?>><? echo "4";?></option>
          </select>
          </td>
          </tr>
        <tr>
          <th>อีเมล์ :</th>
          <td><input type="text" name="student_email" id="student_email" value="<? echo $student_email;?>"/></td>
        </tr>
        <tr>
          <th>เบอร์โทรศัพท์ :</th>
          <td><input type="text" name="student_phone" id="student_phone" value="<? echo $student_phone;?>" /></td>
        </tr>
        <tr>
          <td colspan="2" align="center">
          <input type="hidden" name="hiddenField" id="hiddenField" />
          <input type="submit" name="button" id="button" value="แก้ไขข้อมูล" />
            <input type="reset" name="button2" id="button2" value="ยกเลิก" />
            <input type="hidden" name="student_id" id="student_id" value="<? echo $_GET[student_id]; ?>" /></td>
            </td>
        </tr>
      </table>
	</form>
    </div>
    </div>
<div id="footer"></div>
</div>
</body>
</html>